// cargo dependencies 引入regex
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
use regex::Regex;

fn main() {
    let args: Vec<String> = env::args().collect();
    let file_name = args.get(1).unwrap();
    let path = Path::new(file_name);
    let file = File::open(path).unwrap();

    let rg: Regex = Regex::new(r"\s+").unwrap();
    let mut content = String::new();
    let reader = BufReader::new(file);

    for line in reader.lines() {
        let line_str = line.unwrap();
        let line_str= line_str.as_str();
        let after = rg.replace_all(line_str, " ");
        content.push_str(after.trim());
        content.push(' ');
    }
    println!("{}", content)
}
